namespace KPIS.GERP.WCF.ePayment.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Update0002 : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.InvoiceItem",
                c => new
                    {
                        invoice_item_id = c.Int(nullable: false, identity: true),
                        invoice_id = c.Int(nullable: false),
                        product_id = c.Int(),
                        product_code = c.String(maxLength: 20),
                        product_name = c.String(maxLength: 70),
                        qty = c.Double(nullable: false),
                        exclude_vat_price = c.Double(nullable: false),
                        include_vat_price = c.Double(nullable: false),
                        vat_amount = c.Double(nullable: false),
                        discount_amount = c.Double(nullable: false),
                        exclude_vat_amount = c.Double(nullable: false),
                        include_vat_amount = c.Double(nullable: false),
                        unit = c.String(nullable: false),
                        remark_1 = c.String(),
                        doc_id = c.String(),
                        created_when = c.DateTime(nullable: false),
                        updated_when = c.DateTime(),
                        deleted = c.Boolean(nullable: false),
                        deleted_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.invoice_item_id)
                .ForeignKey("dbo.Invoice", t => t.invoice_id, cascadeDelete: true)
                .Index(t => t.invoice_id);
            
            CreateTable(
                "dbo.Invoice",
                c => new
                    {
                        invoice_id = c.Int(nullable: false, identity: true),
                        invoice_code = c.String(nullable: false, maxLength: 25),
                        po_code = c.String(nullable: false, maxLength: 25),
                        lot_no = c.String(nullable: false, maxLength: 20),
                        date = c.DateTime(nullable: false),
                        supplier_id = c.Int(nullable: false),
                        doc_id = c.String(),
                        created_when = c.DateTime(nullable: false),
                        updated_when = c.DateTime(),
                        deleted = c.Boolean(nullable: false),
                        deleted_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.invoice_id)
                .ForeignKey("dbo.Supplier", t => t.supplier_id, cascadeDelete: true)
                .Index(t => t.supplier_id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.InvoiceItem", "invoice_id", "dbo.Invoice");
            DropForeignKey("dbo.Invoice", "supplier_id", "dbo.Supplier");
            DropIndex("dbo.Invoice", new[] { "supplier_id" });
            DropIndex("dbo.InvoiceItem", new[] { "invoice_id" });
            DropTable("dbo.Invoice");
            DropTable("dbo.InvoiceItem");
        }
    }
}
